home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_217 / stevie / unix.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  171 lines

  1. /*
  2.  * System-dependent routines for UNIX System V Release 3. 
  3.  */
  4.  
  5. #include "stevie.h"
  6. /* #include <termio.h> /* System V */
  7. #include <curses.h>        /* BSD */
  8.  
  9. /*
  10.  * inchar() - get a character from the keyboard 
  11.  */
  12. int
  13. inchar()
  14. {
  15.     char            c;
  16.  
  17.     flushbuf();            /* flush any pending output */
  18.  
  19.     while (read(0, &c, 1) != 1);
  20.  
  21.     return (int) c;
  22. }
  23.  
  24. #define BSIZE   2048
  25. static char     outbuf[BSIZE];
  26. static int      bpos = 0;
  27.  
  28. flushbuf()
  29. {
  30.     if (bpos != 0)
  31.     write(1, outbuf, bpos);
  32.     bpos = 0;
  33. }
  34.  
  35. /*
  36.  * Macro to output a character. Used within this file for speed. 
  37.  */
  38. #define outone(c)       outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  39.  
  40. /*
  41.  * Function version for use outside this file. 
  42.  */
  43. void
  44. outchar(c)
  45.     char            c;
  46. {
  47.     outbuf[bpos++] = c;
  48.     if (bpos >= BSIZE)
  49.     flushbuf();
  50. }
  51.  
  52. void
  53. outstr(s)
  54.     char           *s;
  55. {
  56.     while (*s) {
  57.     outone(*s++);
  58.     }
  59. }
  60.  
  61. void
  62. beep()
  63. {
  64.     if (RedrawingDisabled)
  65.     return;
  66.  
  67.     outone('\007');
  68. }
  69.  
  70. /*
  71.  * remove(file) - remove a file 
  72.  */
  73. void
  74. remove(file)
  75.     char           *file;
  76. {
  77.     unlink(file);
  78. }
  79.  
  80. /*
  81.  * rename(of, nf) - rename existing file 'of' to 'nf' 
  82.  */
  83. void
  84. rename(of, nf)
  85.     char           *of, *nf;
  86. {
  87.     unlink(nf);
  88.     link(of, nf);
  89.     unlink(of);
  90. }
  91.  
  92. void
  93. delay()
  94. {
  95.     /* not implemented */
  96. }
  97.  
  98. static struct termio ostate;
  99.  
  100. void
  101. windinit()
  102. {
  103.     char           *getenv();
  104.     char           *term;
  105.     struct termio   nstate;
  106.  
  107.     if ((term = getenv("TERM")) == NULL || strcmp(term, "vt100") != 0) {
  108.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  109.     exit(1);
  110.     }
  111.     Columns = 80;
  112.     P(P_LI) = Rows = 24;
  113.  
  114.     /*
  115.      * Go into cbreak mode 
  116.      */
  117.     ioctl(0, TCGETA, &ostate);
  118.     nstate = ostate;
  119.     nstate.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
  120.     nstate.c_cc[VMIN] = 1;
  121.     nstate.c_cc[VTIME] = 0;
  122.     ioctl(0, TCSETAW, &nstate);
  123. }
  124.  
  125. void
  126. windexit(r)
  127.     int             r;
  128. {
  129.     /*
  130.      * Restore terminal modes 
  131.      */
  132.     ioctl(0, TCSETAW, &ostate);
  133.  
  134.     exit(r);
  135. }
  136.  
  137. #define outone(c)       outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  138.  
  139. void
  140. windgoto(r, c)
  141.     int             r, c;
  142. {
  143.     r += 1;
  144.     c += 1;
  145.  
  146.     /*
  147.      * Check for overflow once, to save time. 
  148.      */
  149.     if (bpos + 8 >= BSIZE)
  150.     flushbuf();
  151.  
  152.     outbuf[bpos++] = '\033';
  153.     outbuf[bpos++] = '[';
  154.     if (r >= 10)
  155.     outbuf[bpos++] = r / 10 + '0';
  156.     outbuf[bpos++] = r % 10 + '0';
  157.     outbuf[bpos++] = ';';
  158.     if (c >= 10)
  159.     outbuf[bpos++] = c / 10 + '0';
  160.     outbuf[bpos++] = c % 10 + '0';
  161.     outbuf[bpos++] = 'H';
  162. }
  163.  
  164. FILE           *
  165. fopenb(fname, mode)
  166.     char           *fname;
  167.     char           *mode;
  168. {
  169.     return fopen(fname, mode);
  170. }
  171.